/*
 * Estring.java
 *
 * Created on 7 de noviembre de 2007, 19:26
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package score.lang;

import java.text.ParseException;
import java.text.SimpleDateFormat;


/**
 *
 * @author vramirez
 */
public class Estring extends ScoreTaip {
    
    private String value;
    /** Creates a new instance of Estring */
    public Estring(String cad) {
        this.setValue(cad);
    }
    
    public String toYnteger()throws NumberFormatException {
        try{
            Long.parseLong(value);
            return ""+new Ynteger(value);
        }catch(Exception e){
            if(value==null){
                return "nUll";
            }else{
                return value;
            }
        }
    }
    
    public String toDobol()throws NumberFormatException{
        try{
            Double.parseDouble(value);
            return ""+new Dobol(value);
        }catch(Exception e){
            if(value==null){
                return "nUll";
            }else{
                return value;
            }
        }
    }
    
    public String getValue() {
        return value;
    }
    
    public void setValue(String value) {
        this.value = value;
    }
    
    public String toString(){
        if(value==null){
            return "nUll";
        }else if(value.equals("nUll")){
            return value.toUpperCase();
        }else{
            return "'"+value+"'";
        }
    }
    
    public String toDeit() throws ParseException{
        SimpleDateFormat sdf = new SimpleDateFormat("'YYYY/MM/dd'");
        try{
            return sdf.format(sdf.parse(value));
        }catch(Exception e){
            if(value==null){
                return "nUll";
            }else{
                return value;
            }
        }
    }    
}